<template>
	<view class="wrap">
		<view class="orderItem common">
			<view class="innerItem spaceBet">
				<template v-if="currOrderType == 'zxType'">
					<view class="itemConImg posRel defBg">
						<image class="samePar posAbso ltzero" mode="aspectFill" :src="getCloudFilePath(orderDet.objHeadImg)" lazy-load></image>
					</view>
					<view class="itemConDet">
						<view class="itemTit ellip">{{orderDet.objName}}咨询师</view>
						<view class="midCon spaceBet">
							<view>{{zxTypeTxt}}</view>
							<!-- 0：待支付，1：待咨询，6：已完成，7：已取消） -->
							<view class="itemStatus waitPay" v-if="orderDet.payStatus == 0">待支付</view>
							<view class="itemStatus wait" v-if="orderDet.payStatus == 1">待咨询</view>
							<view class="itemStatus hasComp" v-if="orderDet.payStatus == 6">已完成</view>
							<view class="itemStatus" v-if="orderDet.payStatus == 7">已取消</view>
						</view>
						<view class="midCon specCol">¥{{orderDet.money}}/{{orderDet.zxMinute}}分钟</view>
					</view>
				</template>
				<template v-else>
					<view class="itemConImg posRel defBg">
						<image class="samePar posAbso ltzero" mode="aspectFill" :src="getCloudFilePath(orderDet.teaImg)" lazy-load></image>
					</view>
					<view class="itemConDet">
						<view class="itemTit">{{orderDet.tcName}}</view>
						<view class="midCon spaceBet">
							<view>咨询师:{{orderDet.teaUserName}}</view>
							<view class="itemStatus waitPay" v-if="orderDet.status == 0">待支付</view>
							<view class="itemStatus hasComp" v-if="orderDet.status == 1">已完成</view>
							<view class="itemStatus" v-if="orderDet.status == 7">已取消</view>
						</view>
						<view class="midCon" v-if="orderDet.status == 0 || orderDet.status == 7">
							咨询次数{{orderDet.tcTimes}}次
						</view>
						<view class="midCon spaceBet" v-else>
							<text>咨询次数:{{orderDet.tcTimes}}次</text>
							<view class="remainTimes">剩余次数:{{orderDet.restTimes}}次</view>
						</view>
					</view>
				</template>
			</view>
			<!-- 实付款 -->
			<view class="actPay spaceBet">
				<block v-if="orderDet.payStatus == 0 || orderDet.payStatus == 7 || orderDet.status == 0 || orderDet.status == 7">
					<view>应付款</view>
				</block>
				<block v-else>
					<view>实付款</view>
				</block>
				<view class="actPayNum">
					<text class="currPrice"><text class="unit">¥</text>{{orderDet.actMoney}}</text>
				</view>
			</view>
		</view>
		<view class="ogzItem" v-if="orderDet.ogzName != '' && orderDet.ogzName != undefined">
			<view class="ogzName spaceBet">{{orderDet.ogzName}}</view>
			<view class="ogzAdd"><text class="iconfont icon-weizhi"></text><text>{{orderDet.ogzAddress}}</text></view>
		</view>
		<view class="basicInfo common" v-if="currOrderType == 'zxType'">
			<view class="infoTit">咨询信息</view>
			<view class="infoCon">
				<view class="infoItem spaceBet">
					<view class="itemTxt">咨询人信息</view>
					<view>{{zxrList.zxrName}} {{zxrList.zxrMobile}}</view>
				</view>
				<view class="infoItem spaceBet">
					<view class="itemTxt">咨询时间</view>
					<view>{{zxrList.zxDate}} {{zxrList.zxClassTime}}</view>
				</view>
				<view class="infoItem spaceBet">
					<view class="itemTxt">咨询方式</view>
					<view>{{zxTypeTxt}}</view>
				</view>
				<view class="infoItem spaceBet" v-if="orderDet.zxType == 3">
					<view class="itemTxt">咨询室</view>
					<view v-if="orderDet.roomUseId > 0">{{orderDet.roomName}}</view>
					<view class="waitFp" v-else>待分配</view>
				</view>
			</view>
		</view>
		<!-- 订单信息 -->
		<view class="basicInfo common">
			<view class="infoTit">订单信息</view>
			<view class="infoCon">
				<template v-if="currOrderType == 'zxType'">
					<view class="infoItem spaceBet">
						<view class="itemTxt">订单金额</view>
						<view>¥{{orderDet.money}}</view>
					</view>
					<view class="infoItem spaceBet" v-if="orderDet.couponMoney > 0">
						<view class="itemTxt">优惠券抵扣</view>
						<view>¥{{orderDet.couponMoney}}</view>
					</view>
					<view class="infoItem spaceBet" v-if="jfTag == 1 && orderDet.dkPrice > 0">
						<view class="itemTxt">积分抵扣</view>
						<view>¥{{orderDet.dkPrice}}</view>
					</view>
					<view class="infoItem spaceBet" v-if="orderDet.tcDkMoney > 0">
						<view class="itemTxt">咨询套餐抵扣</view>
						<view>¥{{orderDet.tcDkMoney}}</view>
					</view>
				</template>
				<template v-else>
					<view class="infoItem spaceBet">
						<view class="itemTxt">订单金额</view>
						<view>¥{{orderDet.actMoney}}</view>
					</view>
				</template>
				<view class="infoItem spaceBet">
					<view class="itemTxt">实付金额</view>
					<view>¥{{orderDet.actMoney}}</view>
				</view>
				<view class="infoItem spaceBet">
					<view class="itemTxt">下单时间</view>
					<view>{{orderDet.addTime}}</view>
				</view>
				<view class="infoItem spaceBet">
					<view class="itemTxt">订单编号</view>
					<view>{{orderDet.orderNoLocal}}</view>
				</view>
				<view class="infoItem spaceBet" v-if="orderDet.payStatus == 0 || orderDet.status == 0">
					<view class="itemTxt">订单状态</view>
					<view>待支付</view>
				</view>
				<view class="infoItem spaceBet" v-if="orderDet.payStatus == 1">
					<view class="itemTxt">订单状态</view>
					<view>待服务</view>
				</view>
				<view class="infoItem spaceBet" v-if="orderDet.payStatus == 6 || orderDet.status == 1">
					<view class="itemTxt">订单状态</view>
					<view>已完成</view>
				</view>
				<view class="infoItem spaceBet" v-if="orderDet.payStatus == 7 || orderDet.status == 7">
					<view class="itemTxt">订单状态</view>
					<view>已取消</view>
				</view>
				<view class="infoItem spaceBet" v-if="orderDet.payAccount != ''">
					<view class="itemTxt">支付方式</view>
					<view v-if="orderDet.payAccount == 'zfb'">支付宝</view>
					<view v-if="orderDet.payAccount == 'wx'">微信</view>
					<view v-if="orderDet.payAccount == 'compPay'">组合支付</view>
					<view v-if="orderDet.payAccount == 'tcPay'">咨询套餐</view>
				</view>
				<view class="infoItem spaceBet" v-if="orderDet.payTime != ''">
					<view class="itemTxt">付款时间</view>
					<view>{{orderDet.payTime}}</view>
				</view>
				<view class="infoItem spaceBet" v-if="orderDet.remark != ''">
					<view class="itemTxt">备注</view>
					<view>{{orderDet.remark}}</view>
				</view>
			</view>
		</view>
		<button class="comBtn" v-if="orderDet.payStatus == 0 || orderDet.status == 0" @tap="goPay">去支付</button>
		<template v-if="currOrderType == 'zxType'">
			<button class="comBtn spec" v-if="orderDet.payStatus == 6 && orderDet.pjId == ''" @tap="goPjPage">去评价</button>
			<button class="comBtn spec" v-if="orderDet.payStatus == 6 && orderDet.pjId != ''" @tap="viewPj">查看评价</button>
		</template>
		<template v-else>
			<button class="comBtn spec" v-if="orderDet.status == 1 && orderDet.restTimes > 0" @tap="goZxYy">去咨询</button>
		</template>
	</view>
</template>

<script>
	import { getZxOrderInfo } from '@/api/xlzx/index'
	export default {
		data(){
			return{
				orderId:'',
				orderDet:[],
				zxrList:[],
				zxTypeTxt:'',
				isRefreshFlag:false,
				jfTag:-1,
				currOrderType:''//zxType(咨询) zxTcType(咨询套餐)
			}
		},
		onLoad(options){
			this.orderId = options.orderId;
			this.currOrderType = options.currOrderType == undefined ? 'zxType' : options.currOrderType;
			let title = this.currOrderType == 'zxType' ? '咨询订单详情' : '咨询套餐详情';
			setTimeout(()=>{
				uni.setNavigationBarTitle({
					title
				})
			},100)
			this.loadOrderInfo();
		},
		onShow(){
			if(this.isRefreshFlag){
				this.loadOrderInfo();
			}
		},
		onHide(){
			this.isRefreshFlag = false;
		},
		onUnload(){
			uni.removeStorageSync('zxsInfoField');
			uni.removeStorageSync('zxTcInfoField');
			if(this.isRefreshFlag){
				let pages = getCurrentPages();
				let prevPage = pages[pages.length - 2];
				prevPage.$vm.isRefreshFlag = true;
			}
		},
		methods:{
			makePhoneCall(phoneNum){
				uni.makePhoneCall({
					phoneNumber:phoneNum
				})
			},
			//去支付
			goPay(){
				let fromPage = '',jfTag = 0;
				if(this.currOrderType == 'zxType'){
					jfTag = this.orderDet.actMoney == this.orderDet.money ? 0 : 1;
					fromPage = 'zxOrderDet';
				}else{
					fromPage = 'zxTcPayOrder';
				}
				uni.navigateTo({
					url:'/pages/subIndex/orderPay/orderPay?orderId=' + this.orderId + '&fromPage=' + fromPage + '&jfTag=' + jfTag
				})
			},
			//去评价
			goPjPage(){
				let { objName,objHeadImg,actMoney,objId,zxMinute } = this.orderDet;
				var field = { zxsName:objName,zxsImg:objHeadImg,zxTypeTxt:this.zxTypeTxt,zxPrice:actMoney,zxsUserId:objId,zxMinute }
				uni.setStorageSync('zxsInfoField',field);
				uni.navigateTo({
					url:'../addGroupOrderPj/addGroupOrderPj?fromPage=zxOrderDet&orderId=' + this.orderId
				})
			},
			//查看评价
			viewPj(){
				uni.navigateTo({
					url:'../viewOrderPj/viewOrderPj?pjId=' + this.orderDet.pjId + '&currType=zxType'
				})
			},
			//咨询套餐下去咨询预约
			goZxYy(){
				let { teaUserName,teaUserId,ustId } = this.orderDet;
				uni.navigateTo({
					url:'/pages/subIndex/zxsYy/zxsYy?zxsUserId=' + teaUserId + '&zxsName=' + teaUserName + '&fromPageType=zxTcType&ustId=' + ustId
				})
			},
			loadOrderInfo(){
				uni.showLoading({title:'加载中...', mask: true });
				let field = null,url = '';
				if(this.currOrderType == 'zxType'){
					field = {id:this.orderId};
					url = '/order/getOrderDetail'
				}else{
					field = {orderId:this.orderId};
					url = '/tcOrder/getTeaTcOrderDetail';
				}
				getZxOrderInfo(field,url).then(res=>{
					this.orderId = res.data.datas.id;
					this.orderDet = res.data.datas;
					if(this.currOrderType == 'zxType'){
						this.zxrList = res.data.datas.zxrList[0];
						if(this.orderDet.zxType == 1){
							this.zxTypeTxt = '视频咨询';
						}else if(this.orderDet.zxType == 2){
							this.zxTypeTxt = '电话咨询';
						}else{
							this.zxTypeTxt = '面对面咨询';
						}
					}
				}).catch(err=>{
					console.log(err)
				});
			}
		}
	}
</script>
<style lang="scss">
	page{
		background: $pss-bg-primary;
	}
</style>
<style lang='scss' scoped>
	@import '@/static/scss/orderDet.scss';
</style>